//
//  CreatePushButton.m
//  AddressBook
//
//  Created by mac on 2017/8/25.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "CreatePushButton.h"

@implementation CreatePushButton



+(UIViewController *)getCurrentRootViewController{
    UIViewController *result;
    
    UIWindow *topWindow = [[UIApplication sharedApplication] keyWindow];
    if (topWindow.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(topWindow in windows)
        {
            if (topWindow.windowLevel == UIWindowLevelNormal)
                break;
        }
    }
    
    UIView *rootView = [[topWindow subviews] objectAtIndex:0];
    
    id nextResponder = [rootView nextResponder];
    
    if ([nextResponder isKindOfClass:[UIViewController class]])
        
        result = nextResponder;
    
    else if ([topWindow respondsToSelector:@selector(rootViewController)] && topWindow.rootViewController != nil)
        
        result = topWindow.rootViewController;
    
    else
        
        NSAssert(NO, @"ShareKit: Could not find a root view controller.  You can assign one manually by calling [[SHK currentHelper] setRootViewController:YOURROOTVIEWCONTROLLER].");
    
    return result;
}

+(void)singleAlertShowMessage:(NSString *)title message:(NSString *)message alertStyle:(UIAlertControllerStyle )alertStyle isCancel:(NSString *)isCancel actionStyle:(UIAlertActionStyle)actionStyle{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:alertStyle];
    
    [alert addAction:[UIAlertAction actionWithTitle:isCancel style:actionStyle handler:nil]];
    
    [[CreatePushButton getCurrentRootViewController] presentViewController:alert animated:YES completion:nil];
}

+(void)alertShowMessage:(NSString *)title prompting:(NSString *)prompting message:(NSString *)message determine:(NSString *)determine cancel:(NSString *)cancel action:(alertAction) action{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:determine style:UIAlertActionStyleDefault handler:action]];
    
    [alert addAction:[UIAlertAction actionWithTitle:cancel style:UIAlertActionStyleCancel handler:nil]];
    
    [[CreatePushButton getCurrentRootViewController] presentViewController:alert animated:YES completion:nil];
}


@end
